from typing import Optional

from sqlalchemy.orm import Session

from app.db import DbOper
from app.db.models import TagGroup


class TagGroupOper(DbOper):
    """
    消息数据管理
    """

    def __init__(self, db: Session = None):
        super().__init__(db)

    def add(self,
            name: str = None,
            name_display: str = None,
            **kwargs) -> int:
        """
        新增档案数据
        :param name: 标签名
        :param name_display: 标签名(显示)
        """
        kwargs.update({
            "name": name,
            "name_display": name_display,
        })
        return TagGroup(**kwargs).create_get_id(self._db)

    def get_by_name(self, name: str) -> Optional[TagGroup]:
        return TagGroup.get_by_name(self._db, name)
